package com.chandon.T05_timeApi.T01_temporal;

import java.time.*;

/**
 * 描述
 *
 * @author Dong
 * @version 1.0
 * @date 2021-04-27 16:31
 */

public class T04_LocalDateTImeTest {
    public static void main(String[] args) {

//        localDateTimeStaticTest();

        // 支持年月日时分秒纳秒的  plus minxs
        LocalDateTime localDateTime = LocalDateTime.now().plusMinutes(111).minusDays(2);

        System.out.println(localDateTime);
    }

    private static void localDateTimeStaticTest() {
        LocalDateTime localDateTime = LocalDateTime.now();
        // 2021-04-27T16:31:55.944
        System.out.println(localDateTime);

        LocalDate localDate = LocalDate.now();
        LocalTime localTime = LocalTime.now();
        LocalDateTime localDateTime4 = localDate.atTime(localTime);
        LocalDateTime localDateTime5 = localTime.atDate(localDate);


        // 获取指定日期时间的LocalDateTime
        // 1987-09-24T00:00
        LocalDateTime birthday = LocalDateTime.of(1987,9,24,00,0);
        // 使用LocalDate LocalTime构造
        LocalDateTime birthday2 = LocalDateTime.of(LocalDate.of(1987, 9, 24), LocalTime.of(0, 0));
        // 使用Instant时间戳与时区构造
        LocalDateTime localDateTime1 = LocalDateTime.ofInstant(Instant.now(), ZoneId.of("Asia/Shanghai"));
        // 字符串解析
        LocalDateTime localDateTime2 = LocalDateTime.parse("2021-04-27T17:52:48.157");
        // 获取从1970-01-01 00 00 为止的秒数的Localdatetime
        LocalDateTime localDateTime3 = LocalDateTime.ofEpochSecond(1561651, 0, OffsetDateTime.now().getOffset());

        System.out.println(birthday);
        System.out.println(birthday2);
        System.out.println(localDateTime1);
        System.out.println(localDateTime2);
        System.out.println(localDateTime3);

        System.out.println("---------------");
        // 获取年月日时分秒
        // 年
        System.out.println(localDateTime.getYear());
        // 月 getValue()数字
        System.out.println(localDateTime.getMonth());
        // 年第几天
        System.out.println(localDateTime.getDayOfMonth());
        // 月第几天
        System.out.println(localDateTime.getDayOfMonth());
        // 周几
        System.out.println(localDateTime.getDayOfWeek());

        // 几点
        System.out.println(localDateTime.getHour());
        // 几分
        System.out.println(localDateTime.getMinute());
        // 几秒
        System.out.println(localDateTime.getSecond());
    }

}
